<template>
  <div class="gendan">
    <van-nav-bar title="歌单广场" left-arrow @click-left="$router.go(-1)" />
    <div class="goods-title">
      <van-image class="goods-img" fit="contain" :src="goodsList.coverImgUrl" />
      <div class="bq">
        <van-tag plain type="primary" round size="mini" color="#e7aa5a"
          >精品歌单</van-tag
        >
        <p>{{ goodsList.name }}</p>
        <p>{{ goodsList.copywriter }}</p>
      </div>
    </div>
    <div class="quanbo">
      <van-button
        plain
        type="primary"
        round
        color="#d8d8d8"
        @click="showpopup = true"
        >全部歌单</van-button
      >
    </div>
    <div class="godList">
      <van-row>
        <van-col
          span="8"
          v-for="(item, index) in suoyouList"
          :key="index"
          class="col"
          @click="isColClick(index)"
        >
          <van-image
            width="100px"
            height="100px"
            fit="cover"
            :src="item.coverImgUrl"
          />
          <p class="col-name">{{ item.name }}</p>
        </van-col>
      </van-row>
    </div>
    <van-popup v-model="showpopup" position="bottom" class="fenlei">
      <van-row>
        <van-col span="6" v-for="(item, index) in songFenlei" :key="index">{{
          item.name
        }}</van-col>
      </van-row>
    </van-popup>
  </div>
</template>

<script>
import { gedanmusic, remenSong, goodSongList } from '../home'
export default {
  data () {
    return {
      songFenlei: [], // 全部跟单分类
      goodsList: [],
      showpopup: false,
      suoyouList: []
    }
  },
  async created () {
    // 歌单分类
    let res = await gedanmusic()
    console.log(res)
    this.songFenlei = res.data.tags

    // 精品歌单
    let goodres = await goodSongList()
    console.log(goodres)
    this.goodsList = goodres.data.playlists[0]

    this.suoyouList = goodres.data.playlists

    let arr = []
    for (let i = 0; i < goodres.data.playlists.length; i++) {
      arr.push(goodres.data.playlists[i].id)
    }
    console.log(arr)

    this.$store.commit('getXinag', arr)
    let resong = await remenSong({ id: 6452 })
    console.log(resong)
  },
  methods: {
    async isColClick (index) {
      this.$router.push({
        path: '/gendanXiang',
        query: { id: this.$store.state.xiangIds[index] }
      })
    }
  }
}
</script>

<style scoped>
.goods-title {
  height: 120px;

  display: flex;
  background: linear-gradient(
    to right,
    rgb(146, 120, 92),
    rgb(91, 122, 137),
    rgb(103, 90, 67)
  );
}
.goods-img {
  height: 100px;
  margin: 10px;
}
.goods-title p {
  font-size: 12px;
  color: #fff;
}
.van-tag {
  margin-top: 20px;
}
.quanbo {
  margin: 10px;
}
.fenlei {
  font-size: 14px;
  text-align: center;
  line-height: 30px;
}
.col-name {
  margin: 0;
  font-size: 12px;
}
</style>
